//
//  XNStatusListViewModel.swift
//  weibo
//
//  Created by 王向宁 on 16/5/25.
//  Copyright © 2016年 王向宁. All rights reserved.
//

import UIKit

class XNStatusListViewModel: NSObject {
    //定义模型数组
    lazy var statusViewModelArray: [XNStatusViewModel] = [XNStatusViewModel]()
    
    func loadData(finished: (isSuccess: Bool) -> ()) {
        
        HMNetworkTools.sharedTools.loadHomePageData { (responseObject, error) in
            if error != nil {
                //SVProgressHUD.showErrorWithStatus(AppErrorTip)
                
                finished(isSuccess: false)
                return
            }
            
            //print(responseObject)
            //处理数据AFN 已经将数据处理成 oc之后数组或字典
            guard let dict = responseObject as? [String : AnyObject] else {
                
                finished(isSuccess: false)
                return
            }
            
            guard let array = dict["statuses"] as? [[String : AnyObject]] else {
                
                finished(isSuccess: false)
                return
            }
            
            //print(array)
            
            var tempArray = [XNStatusViewModel]()
            
            for item in array {
                let s = XNStatus(dict: item)
                
                //在数组中添加视图模型
                let viewmodl = XNStatusViewModel(status: s)
                
                tempArray.append(viewmodl)
            }
            
            self.statusViewModelArray = tempArray
            
            finished(isSuccess: true)
            
          //  self.tableView.reloadData()
        }
    }


}
